<template>
  <el-drawer v-model="drawer" size="40%" class="elDrawer">
    <template #header>
      <div style="display:flex;align-items:center">
          <el-icon style="margin-right:10px;"><UserFilled /></el-icon>
          <h4>角色扮演</h4>
      </div>
    </template>
    <template #default>
      <div >
        <el-tabs v-model="choseName" class="demo-tabs" @tab-change="tabClick">
          <el-tab-pane  v-for="(item,index) in tabList" :key="index" :name="item.Name" :label="item.Name">
            <div class="choseRole">
              <div class="role-wrap" v-for="(item, index) in roleList" :key="index">
                <div class="role-top">
                  <p class="role">{{item.Title}}</p>
                </div>
                <el-divider border-style="dotted" />
                <div class="role-bottom">
                  <p class="explain">{{item.SystemRole}}</p>
                </div>
                <div>
                  <el-button type="primary" plain  @click="roleClick(item)" class="tryAConversation">尝试对话</el-button>
                </div>
              </div>
            </div>
          </el-tab-pane>
        </el-tabs>
      </div>
    </template>
  </el-drawer>
</template>

<script>
import { connrequest } from '../../api/connrequest'
export default {
  data(){
    return{
      drawer: false,
      choseName: '',
      tabList: [],
      roleList: []
    }
  },
  created(){
  },
  methods:{
    async GetAiTemplateClass(){
      const res = await connrequest('GetAiRoleClass')
      this.tabList = res.Data.filter(item => item.IsNotShow !== 1)
      let name = res.Data[0]?.Name
      this.tabList.unshift({Name: '常用角色'})
      this.choseName = name
      this.GetAiTemplateRes(name)
    },
    async GetAiTemplateRes(ResName){
      const data = {
        Data:{
          ResName
        }
      }
      const res = await connrequest('GetAiRoleRes', data)
      // 过滤掉角色分类中每个分类里边每条数据的IsNotShow属性值为1的数据
      this.roleList = res.Data.filter(item => item.IsNotShow !== 1)
    },
    cancelClick(){
      this.drawer = false
    },
    async openDrawer(){
      await this.GetAiTemplateClass()
      this.drawer = true
    },
    roleClick(row){
      this.$emit('roleDialogue', row)
    },
    tabClick(name){
      this.tabName = name
      if(name === '常用角色'){
        this.GetCommonAiRole()
      }else{
        this.GetAiTemplateRes(name)
      }
    },
    async GetCommonAiRole(){
      const res = await connrequest('GetCommonAiRole')
      this.roleList = res.Data
    }
  }
}
</script>

<style lang="scss" scoped>
:global(.el-drawer__header) {
  padding-top: 0px;
  margin-bottom: 0px !important;
}
:global(.el-drawer__body){
  padding-top: 0px !important;
}
.choseRole{
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(318px, 1fr));
  grid-gap: 15px; /* 设置行和列之间的间距为 15px */
  grid-template-rows: repeat(auto-fit, minmax(210px, 1fr));
  max-height: calc(100vh - 250px);
  border-radius: 5px;
  overflow-y: auto;
  padding: 0 0 0 15px;
  color: #8c8c8c;
  background-color: #fff;

  .role-wrap{
    margin-right: 15px;
    border: 1px solid #f0f0f0;
    padding: 15px;
    border-radius: 5px;
  }
  .choseRole::after {
    content: "";
    flex: auto;
  }
  .role{
    margin: 0px 0 -10px;
    font-size: 16px;
    color: #141414;
    white-space: nowrap; /* 不换行 */
    overflow: hidden; /* 隐藏溢出部分 */
    text-overflow: ellipsis; /* 显示省略号 */
  }
  .introduce{
    font-size: 14px;
    padding-bottom: 10px;
    border-bottom: 1px solid #f0f0f0;
    white-space: nowrap; /* 不换行 */
    overflow: hidden; /* 隐藏溢出部分 */
    text-overflow: ellipsis; /* 显示省略号 */
  }
  .explain{
    height: 75px;
    overflow-y: auto;
    font-size: 12px;
    color: #000;
    line-height: 25px;
    display: -webkit-box;
    margin-top: -10px;
    // -webkit-line-clamp: 3; /* 指定显示的行数 */
    // -webkit-box-orient: vertical; /* 设置为垂直方向 */
    // overflow: hidden;
    // text-overflow: ellipsis;
  }
  .tryAConversation{
    border-radius: 10px;
  }
  ::-webkit-scrollbar {
    width: 0px; 
  }
}
:deep(.el-tabs__nav:first-child::before) {
  content: "" !important;
}
</style>